package com.adgox.tiantianbiting.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by tang on 2019/1/7.
 */

public class TimeUtils {

    //将秒数转成 MM:ss格式
    public static String SecondToTime(int second) {
        int minute = second / 60;
        int newSecond = second % 60;

        String resultMin = minute >= 10 ? "" + minute : "0" + minute;
        String resultSec = newSecond >= 10 ? "" + newSecond : "0" + newSecond;

        return resultMin + ":" + resultSec;
    }

    //将豪秒数转成 MM:ss格式
    public static String MSToTime(int ms) {
        int second = ms / 1000;
        int minute = second / 60;
        int newSecond = second % 60;

        String resultMin = minute >= 10 ? "" + minute : "0" + minute;
        String resultSec = newSecond >= 10 ? "" + newSecond : "0" + newSecond;

        return resultMin + ":" + resultSec;
    }

    public static String MstoHMS(long ms) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
        Date date = new Date(ms);
        String s = simpleDateFormat.format(date);
        return s;
    }

    //将秒转成HH:mm:ss格式
    public static String SecondToHms(int second) {

        int hour = second / 3600;

        int minute = (second % 3600) / 60;

        int leftSecond = second - (60 * minute) - (3600 * hour);

        return "" + (hour >= 10 ? hour : "0" + hour) + ":"
                +(minute >= 10 ? minute : "0" + minute) +":"+
                (leftSecond >= 10 ? leftSecond : "0" + leftSecond);

    }

}
